
<template>
	<view>
		<uni-popup ref="popupr" type="bottom" background-color="#fff" @change="bindClose">
			<view class="popup-content" style="height:930rpx">
				<view class="downs" @click="bindClose($event)">
					<view class="downs-btn"></view>
					<view class="tits">{{ tits }}</view>
				</view>
				<view class="drawer-search">
					<image class="left-icon" src="@/static/images/search_black.png"> </image>
					<input v-model="keywords" @input="searchFuc" :placeholder="'请输入电梯关键词'" placeholder-style="color:#ccc" />
					<view class="clear" @click.stop="clearKeywords" v-if="keywords.length">
						<uni-icons color="#999999" type="clear" />
					</view>
				</view>
				<view class="base-line"></view>

				<scroll-view scroll-y="true" style="height: 680rpx; padding-top: 36rpx">
					<view class="base-rows">
						<view class="name_row" v-for="(item,i) in seleObjArr" :key="i" @click.stop="selectFunc(item,i)">
							<view class="name_row_item1" >
								<block v-if="!item.floorElevatorId || item.floorElevatorId === -1">
									<uni-icons v-show="item.acts" color="#0091ff" size="20" style="margin-right:4rpx" type="checkbox-filled" />
									<uni-icons v-show="!item.acts" color="#ccc" size="20" style="margin-right:4rpx" type="circle" />
								</block>
								<uni-icons v-if="item.floorElevatorId && item.floorElevatorId !== -1" size="20" color="#ccc" style="margin-right:4rpx" type="checkbox" />
							</view>
							<!-- <view class="name_row_item2">{{item.elevatorAddress}}</view> -->
							<rich-text class="name_row_item2" :nodes="actSearch(item)"></rich-text>
						</view>
						<view class="name_row_empty" v-if="seleObjArr.length === 0">
							<view>
								<image style="width: 64rpx;height: 64rpx;" src="/static/images/default.png"></image>
							</view>
							<view class="empty_tit">暂无数据</view>
						</view>
					</view>

				</scroll-view>

				<view class="bottoms">
					<!-- <view class="reSet" @click="bindClose($event, 1)">取消</view> -->
					<view class="submit" @click="submitDate">确认</view>
				</view>
			</view>
		</uni-popup>

	</view>
</template>

<script>
export default {
	props: {
		dateCurr: {// 1年月日 2年周 3年月
			type: Number,
			default: 1
		},
		showState: {
			type: Boolean,
			default: false,
		},
		tits: {
			type: String,
			default: '搜索电梯'
		},
		seleArrs: {
			type: Array,
			default: []
		},
		selectedArr:{
			type: Array,
			default: []
		},
		seleShows:{
			type:Boolean,
			default: []
		}
	},
	data() {
		return {
			selectValue: [],// 日期选择
			selectDate: null,
			keywords: '',
			seleObjArr: [],
			seleObjArrTwo:[]
		};
	},
	watch:{
		seleShows(val) {
			if (val) {
				this.$refs.popupr.open();
				this.$nextTick(() => {
					this.selectedArr.forEach(element => {
						this.seleObjArr.forEach(item => {
							if (element.id == item.id) {
								item.acts = true;
							}
						});
					});
				});
			}
		},
		seleArrs(val) {
			this.seleObjArr = val;
			this.seleObjArrTwo = JSON.parse(JSON.stringify(val));
		},
	},
	methods: {
		bindChange(e) {
			this.selectDate = e.detail.value;
		},
		selectFunc(obj,i) {
			if (obj.floorElevatorId && obj.floorElevatorId !== -1) {
				uni.showToast({ title: '该电梯已被关联', icon: 'none', });
				return;
			}

			this.seleObjArr[i].acts = !this.seleObjArr[i].acts;
			this.$forceUpdate();
		},
		bindClose(e,) {
			if (!e.show) {
				// this.$refs.popupr.close()
				this.keywords = '';
				this.seleObjArr = this.seleObjArrTwo;
				this.seleObjArr.forEach(item => {
					item.acts = false;
				});
				this.$emit('bindClose', false);
			}
		},
		// 搜索关键词高亮
		actSearch(item) {
			let str = item.elevatorAddress || '';
			let resultStrs = str.replaceAll(this.keywords, '<span style=\'color:#0091ff;\'>' + this.keywords + '</span>');
			return resultStrs;
		},
		searchFuc() {
			console.log('searchFuc', this.keywords);
			this.seleObjArr = this.seleObjArrTwo.filter(item => {
				return item.elevatorAddress.indexOf(this.keywords) != -1;
			});
		},
		clearKeywords() {
			this.keywords = '';
			this.seleObjArr = this.seleObjArrTwo;
		},
		// 确认
		submitDate() {
			this.$emit('selectChecd', this.seleObjArr);
			this.$refs.popupr.close();
		},
	}

};
</script>

<style lang="scss" scoped>

.popup-content {
	display: flex;
	flex-direction: column;
	padding: 30rpx;
	// height: 50px;
	background-color: #fff;
	border-radius: 8rpx 8rpx 0rpx 0rpx;
	position: relative;
	.tits{
		font-weight: bold;
		color: #333;
		font-size: 32rpx;
}
	.name_row_empty {
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		height: 200rpx;
		font-size: 26rpx;
		color: #999999;
	}
	.drawer {
		z-index: 1002;
		width: calc(100%);
		margin: 0 auto;
		background-color: #fff;
		border-top-right-radius: 8rpx;
		border-top-left-radius: 8rpx;
		animation: scaleFrames 0.3s ease;
		padding-top: 0rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		letter-spacing: 0.1rpx;

		// padding-bottom: 10rpx;
		// overflow-y: auto;
		.down {
			width: 100%;
			padding: 18rpx 0;

			.down-btn {
				width: 64rpx;
				height: 10rpx;
				background: #d8d8d8;
				border-radius: 6rpx;
				margin: 0 auto;
			}
		}

		&-search {
			width: 100%;
			height: 68rpx;
			margin-top: 10rpx;
			background: #f6f6f6;
			border-radius: 8rpx;
			margin-top: 20rpx;
			margin-bottom: 10rpx;
			display: flex;
			align-items: center;
			color: #333;

			.left-icon {
				width: 40rpx;
				height: 40rpx;
				padding: 16rpx;
			}

			input {
				flex: 1;
				font-size: 26rpx;
			}

			.clear {
				font-size: 24rpx;
				padding: 16rpx;
			}
		}

		.empty {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			width: 100%;
			margin-top: 100rpx;

			.circle {
				width: 112rpx;
				height: 112rpx;
			}

			image {
				width: 112rpx;
				height: 112rpx;
			}

			.title {
				font-size: 26rpx;
				color: #666;
				font-weight: normal;
				margin-top: 10rpx;
			}
		}
	}
	.base-line {
		position: absolute;
		left: 0;
		right: 0;
		top:180rpx;
		
		width: 100%;
		height: 18rpx;
		background-color: #F3F6F8;
		border-bottom: 8rpx solid #F3F6F8;
	}
	.base-rows{
		// margin-top: 20rpx;
		.name_row {
			display: flex;
			align-items: center;
			// margin-top: 20rpx;
			border-bottom: 2rpx#E9E9E9 solid;
			padding: 26rpx 0;

			.name_row_item1 {
				width: 50rpx;
				font-size: 24rpx;
				color: #333333;
			}

			.name_row_item2 {
				flex: 1;
				font-size: 26rpx;
				color: #333333;
			}
		}
	}

	.downs {
		width: 100%;

		.downs-btn {
			width: 64rpx;
			height: 10rpx;
			background: #d8d8d8;
			border-radius: 6rpx;
			margin: 0 auto;
		}
	}

	.bottoms {
		display: flex;
		height: 100rpx;
        border-top: 2rpx solid #eee;
        line-height: 100rpx;
        align-items: center;
		position: absolute;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 0 20rpx;
		.submit {
			display: flex;
			flex: 1;
			height: 70rpx;
			justify-content: center;
			align-items: center;
			border-radius: 8rpx;
			font-size: 28rpx;
		}

		.reSet {
			background-color: #f5fbff;
			color: #0091ff;
			margin-right: 10rpx;
		}

		.submit {
			background-color: $theme-color;
			color: #fff;
		}
	}
}
</style>